//
//  BlockViewController.m
//  GCD
//
//  Created by fangyuan ding on 2020/8/11.
//  Copyright © 2020 fangyuan ding. All rights reserved.
//

#import "BlockViewController.h"

@interface BlockViewController ()

@end

@implementation BlockViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    __weak typeof(self) weakSelf = self;
    //如果在block内部使用延时操作还使用弱指针的话会取不到该弱指针，需要在block内部再将弱指针强化一下
    __strong typeof(self) strongSelf = weakSelf;
//    [self test1];
//    [self test2];
    [self test3];
    
//    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
//        NSLog(@"测试block");
//    }];
//    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
   
}

- (void)test1{
    int a = 10;
    void (^block)(void) = ^{
        NSLog(@"a is %d",a);
    };
    block();
    
}
- (void)test2{
    __block int a = 10;
    void (^block)(void) = ^{
        NSLog(@"a is %d",a);
    };
    a = 20;
    block();
   
    
}



- (void)test3{
    static int a = 10;
    void (^block)(void) = ^{
        NSLog(@"a is %d",a);
    };
    a = 20;
    block();
    
}
@end
